#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include "server.h"

int user_ls (int sock_fd)
{
	int i, user_num, online_num, tmp;

	for (i = 0; strlen(users[i].name) > 0; i++);
	user_num = i;
	send(sock_fd, &user_num, sizeof(int), 0); 

	for (i = 0; i < user_num; i++){
		if ( users[i].sock_fd > 0) 
		{
			tmp = strlen(users[i].name);
			send(sock_fd, &tmp, sizeof(int), 0);
			send(sock_fd, &users[i].name, tmp, 0);
			tmp = 1;
			send(sock_fd, &tmp, sizeof(int), 0);
		}
	}

	for (i = 0; i < user_num; i++){
		if ( users[i].sock_fd < 0) 
		{
			tmp = strlen(users[i].name);
			send(sock_fd, &tmp, sizeof(int), 0);
			send(sock_fd, &users[i].name, tmp, 0);
			tmp = 0;
			send(sock_fd, &tmp, sizeof(int), 0);
		}
	}

	printf("user_ls:%d\n", user_num);
}
